<?php
$headerMat = "[/]\nMetadata/SourceName = CBE Vigilent Motes\nuuid = " . $_POST['uuid'] . "\n\n";
$driver = "[/" . $_POST['username'] . "]\n" . "type = vigilentLive.VigilentLiveDriver\n\n";
$metadata = "Metadata/Extra/Project = " . $_POST['username'] . "\nProperties/Timezone = " . $_POST['timezone'] . "\n\n"; 
$units = "#unique units\n" . $_POST['units'] . "\n\n";
$calibrations = "#unique calibrations\n" . $_POST['calibrations'] . "\n\n";
$report = "[report 0]\nReportDeliveryLocation = http://new.openbms.org/backend/add/SA2nYWuHrJxmPNK96pdLKhnSSYQSPdALkvnA";
$data = $headerMat.$driver.$metadata.$units.$calibrations.$report;
$allData = json_encode($_POST);

$file = "/var/www/pmpsetup/files/" . $_POST['username'] . "_config.ini";
$savedFile = "/var/www/pmpsetup/files/" . $_POST['username'] . "_config.saved"; 
$smapRun = "/var/www/pmpsetup/files/startSmap.sh";

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");

$fp2 = fopen($savedFile, "w") or die("Couldn't open $savedFile for writing!");
fwrite($fp2, $allData) or die("Couldn't write values to file!");

$fp3 = fopen($smapRun, "w") or die("Couldn't open $smapRun for writing!");
$cmd = "cd /var/www/pmpsetup/files\ntwistd -n smap " . $file;
fwrite($fp3, $cmd) or die("Couldn't write to smap file");

fclose($fp);
fclose($fp2); 
fclose($fp3);
?>